#!/bin/bash
if [ "$(whoami)" == "root" ]
then
    cp /etc/apt/sources.list /etc/apt/sources.list.bak;
    sed -i 's/http:\/\/security.ubuntu.com/http:\/\/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list
    sed -i 's/http:\/\/archive.ubuntu.com/http:\/\/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list
    apt update -y
    apt upgrade -y
    apt install language-pack-zh-hans* manpages manpages-dev manpages-zh locales apt-transport-https ca-certificates gnupg lsb-release wget curl zsh git make gcc g++ -y;
    update-locale "LANG=en_US.UTF-8";
    cp /etc/locale.gen /etc/locale.gen.bak;
    sudo sh -c 'echo "en_US.UTF-8 UTF-8\nzh_CN.UTF-8 UTF-8" >/etc/locale.gen';
    locale-gen;
    dpkg-reconfigure --frontend noninteractive locales;
    Housename=`getent passwd ${SUDO_UID:-$(id -u)} | cut -d: -f 1`
    House=`getent passwd ${SUDO_UID:-$(id -u)} | cut -d: -f 6`
    git clone --depth=1 https://github.com/ohmyzsh/ohmyzsh.git /etc/oh-my-zsh
	cp /etc/oh-my-zsh/templates/zshrc.zsh-template /etc/skel/.zshrc
	sed -i 's|$HOME/.oh-my-zsh|/etc/oh-my-zsh|g' /etc/skel/.zshrc
    sed -ie 's/^export ZSH=\/etc\/oh-my-zsh.*$/&\nexport ZSH_CACHE_DIR="${XDG_CACHE_HOME:-$HOME\/.cache}\/oh-my-zsh"/' /etc/skel/.zshrc
    sed -i '/^ZSH_THEME=.*/c ZSH_THEME="ys"' /etc/skel/.zshrc
    sed -i 's/^#[]\(DISABLE_AUTO_UPDATE="true"\)/\1/' /etc/skel/.zshrc
    echo 'alias ll="ls -lahF --color --time-style=long-iso"' >> /etc/skel/.zshrc
    git clone --depth=1 https://github.com/zsh-users/zsh-syntax-highlighting.git /etc/oh-my-zsh/custom/plugins/zsh-syntax-highlighting
    git clone --depth=1 https://github.com/zsh-users/zsh-autosuggestions /etc/oh-my-zsh/custom/plugins/zsh-autosuggestions
    git clone --depth=1 https://github.com/zsh-users/zsh-completions /etc/oh-my-zsh/custom/plugins/zsh-completions
    [ -z "`grep "autoload -U compinit && compinit" /etc/skel/.zshrc`" ] && echo "autoload -U compinit && compinit" >> /etc/skel/.zshrc
    sed -i '/^plugins=/c\plugins=(git sudo z zsh-syntax-highlighting zsh-autosuggestions zsh-completions)' /etc/skel/.zshrc
    echo -e "\nexport LANG=\"zh_CN.UTF8\"" >>/etc/skel/.zshrc
    echo -e 'function git_prompt_info() {\n  ref=$(git symbolic-ref HEAD 2> /dev/null) || return\n  echo "$ZSH_THEME_GIT_PROMPT_PREFIX${ref#refs/heads/}$ZSH_THEME_GIT_PROMPT_SUFFIX"\n}' >/etc/oh-my-zsh/custom/disable_git_info.zsh
    sed -i '/^SHELL=.*/c SHELL=/bin/zsh' /etc/default/useradd
    cp /etc/skel/.zshrc $House/.zshrc
    chmod 777 $House/.zshrc
    cp /etc/skel/.zshrc /root/.zshrc
    chsh -s /usr/bin/zsh $House
    #curl -fsSkL https://get.docker.com/ | bash
fi